#include <bits/stdc++.h>
using namespace std;
using LL = long long;
#define FOR(i, x, y) for (decay<decltype(y)>::type i = (x), _##i = (y); i < _##i; ++i)
#define FORD(i, x, y) for (decay<decltype(x)>::type i = (x), _##i = (y); i > _##i; --i)
#ifdef zerol
#define dbg(x...) do { cout << "\033[32;1m" << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif

int n;

const int N = 8e3+50;

char s[N];

vector<int> a[200];

int has[200][N], sum[200][N];

int main() {
    // int t;

    scanf("%d%s", &n, s);

    for (int i=0; i<n; ++i) {
        has[s[i]][i] = 1;
    }

    for (int i=n-1; i>=0; --i) {
        for (int j=0; j<200; ++j)
            sum[j][i] = sum[j][i+1] + has[j][i];
    }

    const char *ss = "RGB";
    LL ans = 0;
    for (int i=0; i<n; ++i) {
        for (int j=i+1; j<n; ++j) {
            if (s[i] == s[j])
                continue;
            for (int k=0; k<3; ++k) {
                if (ss[k] != s[i] && ss[k] != s[j]) {
                    ans += sum[ss[k]][j+1] - has[ss[k]][j+j-i];
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}
